package com.puzzlebazar.server;

import java.util.LinkedList;
import java.util.Vector;

import com.puzzlebazar.client.puzzleinfo.PuzzleInfo;
import com.puzzlebazar.client.puzzleinfo.PuzzleInfo.Status;

public class CompositePuzzleListFilter extends PuzzleListFilter {

	private Vector<PuzzleListFilter> children = new Vector<PuzzleListFilter>(); 
	
	/**
	 * Adds a new child to this composite
	 * 
	 * @param child The filter to add as a child
	 */
	public void add( PuzzleListFilter child ) {
		children.add( child );
	}
	
	@Override
	public void addGenre(String genre) {
		for( PuzzleListFilter child: children ) {
			child.addGenre( genre );
		}
	}

	@Override
	public void addStatus(Status status) {
		for( PuzzleListFilter child: children ) {
			child.addStatus( status );
		}
	}

	@Override
	public LinkedList<PuzzleInfo> runQuery() {
		LinkedList<PuzzleInfo> result = new LinkedList<PuzzleInfo>();
		for( PuzzleListFilter child: children ) {
			LinkedList<PuzzleInfo> queryResult = child.runQuery();
			mergeInto( result, queryResult );
		}
		return result;
	}

	@Override
	public void setAuthorEmail(String authorEmail) {
		for( PuzzleListFilter child: children ) {
			child.setAuthorEmail( authorEmail );
		}
	}

	@Override
	public void setGenres(Vector<String> genres) {
		for( PuzzleListFilter child: children ) {
			child.setGenres( genres );
		}
	}

	@Override
	public void setNeedModelInDatastore(Boolean needModelInDatastore) {
		for( PuzzleListFilter child: children ) {
			child.setNeedModelInDatastore( needModelInDatastore );
		}
	}

	@Override
	public void setType(Type type) {
		for( PuzzleListFilter child: children ) {
			child.setType( type );
		}
	}

	@Override
	public void setStatuses(Vector<Status> statuses) {
		for( PuzzleListFilter child: children ) {
			child.setStatuses( statuses );
		}
	}



}
